import { baseRequestClient, requestClient } from '#/api/request';

export namespace Location {
  export interface Params {
    attr1: null;
  }

  export interface Row {
    flag: string;
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: Params;
    locationId: Long;
    locationCode: string;
    locationName: string;
    warehouseId: number;
    area: number;
    areaFlag: string;
    frozenFlag: string;
    attr2: null;
    attr3: number;
    attr4: number;
    children: null;
    attr1: boolean | null | string;
  }

  export interface GetListParams {
    pageNum: number;
    pageSize: number;
    locationId: string;
  }
  export interface GetListReturn {
    total?: number;
    rows?: Row[];
    code: number;
    msg: string;
  }
}

// 获取列表
export const getLocationTableList = (params: Location.GetListParams) =>
  requestClient.get<Location.GetListReturn>('/mes/wm/location/list', {
    params,
  });

// 修改库区设置
export const updateLocation = (data: Location.Row) =>
  requestClient.put<Location.GetListReturn>('/mes/wm/location', data);
export const updateLocationStatus = (data: {
  frozenFlag: string;
  locationId: string;
}) => requestClient.put<Location.GetListReturn>('/mes/wm/location', data);

// 增加库区设置
export const addLocation = (data: Location.Row) =>
  requestClient.post<Location.GetListReturn>('/mes/wm/location', data);

// 删除库区设置
export const deleteLocation = (id: string) =>
  requestClient.delete<Location.GetListReturn>(`/mes/wm/location/${id}`);

// 获取自动生成编码
export const getLocationCode = () =>
  baseRequestClient.get<any>('/system/autocode/get/LOCATION_CODE');

export const setProductMixing = (data: Location.Row) => {
  requestClient.post<Location.GetListReturn>(
    `/mes/wm/location/setProductMixing?locationId=${data.locationId}&flag=${data.flag}`,
  );
};

export const setBatchMixing = (data: Location.Row) => {
  requestClient.post<Location.GetListReturn>(
    `/mes/wm/location/setBatchMixing?locationId=${data.locationId}&flag=${data.flag}`,
  );
};
